{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "toc": "true"
   },
   "source": [
    "# Table of Contents\n",
    " <p>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "%config InlineBackend.figure_format='retina'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import GPy\n",
    "import numpy as np\n",
    "\n",
    "nobsv=3000\n",
    "X = np.random.normal(size=(nobsv,2))\n",
    "Y = np.random.normal(size=(nobsv,1))\n",
    "se = GPy.kern.RBF(2, lengthscale=1.0)\n",
    "\n",
    "gp_se = GPy.models.GPRegression(X, Y, se)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2 loops, best of 3: 1.34 s per loop\n"
     ]
    }
   ],
   "source": [
    "import gc\n",
    "gc.collect()\n",
    "%timeit -n2 gp_se.parameters_changed()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "rq = GPy.kern.RatQuad(2, lengthscale=1.0, power=1.0)\n",
    "gp_rq = GPy.models.GPRegression(X, Y, rq)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 loop, best of 3: 1.76 s per loop\n"
     ]
    }
   ],
   "source": [
    "%timeit gp_rq.parameters_changed()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "gp_sum = GPy.models.GPRegression(X, Y, se+rq)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 loop, best of 3: 1.85 s per loop\n"
     ]
    }
   ],
   "source": [
    "%timeit gp_sum.parameters_changed()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "gp_prod = GPy.models.GPRegression(X, Y, se*rq)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 loop, best of 3: 1.95 s per loop\n"
     ]
    }
   ],
   "source": [
    "%timeit gp_prod.parameters_changed()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "se2 = GPy.kern.RBF(2, lengthscale=1.0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "gp_sum = GPy.models.GPRegression(X, Y, se+se2+rq)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 loop, best of 3: 2.1 s per loop\n"
     ]
    }
   ],
   "source": [
    "%timeit gp_sum.parameters_changed()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "gp_prod = GPy.models.GPRegression(X, Y, (se+se2)*rq)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 loop, best of 3: 2.19 s per loop\n"
     ]
    }
   ],
   "source": [
    "%timeit gp_prod.parameters_changed()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "semask = GPy.kern.RBF(1, lengthscale=1.0, active_dims=[0])\n",
    "rqmask = GPy.kern.RatQuad(1, lengthscale=1.0, power=1.0, active_dims=[1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " /Users/imolk/bin/venv_python3/lib/python3.5/site-packages/GPy/core/gp.py:86: UserWarning:Your kernel has a different input dimension 1 then the given X dimension 2. Be very sure this is what you want and you have not forgotten to set the right input dimenion in your kernel\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 loop, best of 3: 1.24 s per loop\n"
     ]
    }
   ],
   "source": [
    "gp = GPy.models.GPRegression(X, Y, semask)\n",
    "%timeit gp.parameters_changed()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 loop, best of 3: 1.94 s per loop\n"
     ]
    }
   ],
   "source": [
    "gp = GPy.models.GPRegression(X, Y, semask+rqmask)\n",
    "%timeit gp.parameters_changed()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 loop, best of 3: 1.29 s per loop\n"
     ]
    }
   ],
   "source": [
    "sefix = GPy.kern.RBF(2, lengthscale=1.0)\n",
    "sefix.variance.fix()\n",
    "gp = GPy.models.GPRegression(X, Y, sefix)\n",
    "%timeit gp.parameters_changed()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 2.46 s, sys: 168 ms, total: 2.63 s\n",
      "Wall time: 1.31 s\n"
     ]
    }
   ],
   "source": [
    "%time gp.parameters_changed()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "python3 venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.1"
  },
  "nav_menu": {},
  "toc": {
   "navigate_menu": true,
   "number_sections": true,
   "sideBar": true,
   "threshold": 6,
   "toc_cell": true,
   "toc_section_display": "block",
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
